#include "MyString.h"
#include <string.h>
#include <stdio.h>
#include <stdbool.h>

void InitMyString(MyStr *s)
{
    s->len = 0; 
    memset(s->str, 0, Size);
}

void InsertStr(MyStr *s, const char *newStr)
{
    int slen = strlen(newStr);
    s->len = Size - 1 > slen ? slen : Size - 1;
    strncpy(s->str, newStr, Size - 1);
}

void PrintStr(MyStr *s, bool HaveEnter)
{
    if (HaveEnter)
    {
        printf("%s\n", s->str);
    }
    else
    {
        printf("%s", s->str);
    }
}

void GetStr(MyStr *s)
{
    InitMyString(s);
    char c = 0;
    //读到回车结束
    while ((c = getchar()) != '\n' && s->len < Size - 1)
    {
        s->str[s->len++]=c;
    }
}

